
# 导入基类
from base.base import Base
from selenium.webdriver.common.by import By
from time import sleep

# 导入页面类继承基类
class GeneralProlemPage(Base):

    # 定位商品管理
    goodsmanager = (By.XPATH, '//span[text()="商场管理"]')
    def clickgoodsmanager(self):
        self.loc_ele(self.goodsmanager).click()

    # 定位通用问题
    generalprolem = (By.XPATH, '//span[text()="通用问题"]')

    def clickgeneralprolem(self):
        self.loc_ele(self.generalprolem).click()

    # 定位添加通用问题的按钮
    addgeneralprolembutton  = (By.CSS_SELECTOR, '#app > div > div.main-container > section > div > div.filter-container > button:nth-child(3)')
    def clickaddprolembutton(self):
        self.loc_ele(self.addgeneralprolembutton).click()

    # 定位问题输入框
    proleminput = (By.CLASS_NAME, "el-input__inner")
    def inputprolemcontent(self, c):
        eles = self.loc_eles(self.proleminput)
        ele = eles[3]
        ele.send_keys(c)

    # 定位回复输入框
    inputreplycontent = (By.CLASS_NAME, "el-textarea__inner")
    def inputreplycontentbusiness(self, c):
        ele = self.loc_ele(self.inputreplycontent)
        ele.send_keys(c)

    # 定位确定按钮
    ensurebutton = (By.XPATH, '/html/body/div[1]/div/div[2]/section/div/div[4]/div/div[3]/div/button[2]')
    def clickensurebutton(self):
        self.loc_ele(self.ensurebutton).click()

    # 断言用到的元素
    dy = (By.XPATH, '//table[@class="el-table__body"]/tbody/tr[1]/td[2]/div')
    def getdycontent(self):
        return self.loc_ele(self.dy).text

    # 断言用到的元素
    dy2 = (By.CLASS_NAME, "el-form-item__error")
    def getdy2content(self):
        return self.loc_ele(self.dy2).text

    # 操作业务的方法
    def addprolembusiness(self, q, r):
        self.clickgoodsmanager()
        sleep(1)
        # 点击通用问题菜单
        self.clickgeneralprolem()
        sleep(1)
        # 点击添加按钮
        self.clickaddprolembutton()
        # 输入问题
        self.inputprolemcontent(q)
        # 输入回复
        self.inputreplycontentbusiness(r)
        sleep(2)
        # 点击确定按钮
        self.clickensurebutton()
        sleep(3)